package com.auctionhaus

import grails.test.*

class CustomerTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testEmailAddressNotValid() {

        mockDomain(Customer)
        def c = new Customer(emailAddress:"kimkardashian",password:"password")
        c.validate()
        assertTrue c.hasErrors()
        assertTrue c.errors.hasFieldErrors("emailAddress")
    }
    void testEmailAddressIsValid() {

        mockDomain(Customer)
	    def c = new Customer(emailAddress:"kim@kardashian.com",password:"password", date:new Date())
        c.validate()
        assertFalse c.hasErrors()
        assertFalse c.errors.hasFieldErrors("emailAddress")
    }

    void testPasswordTooShort() {

        mockDomain(Customer)
        def c = new Customer(emailAddress:"kim@kardashian.com",password:"short", date:new Date())
        c.validate()
        assertTrue c.hasErrors()
        assertTrue c.errors.hasFieldErrors("password")
    }

    void testPasswordTooLong() {

        mockDomain(Customer)
        def c = new Customer(emailAddress:"kim@kardashian.com",password:"longPassword", date:new Date())
        c.validate()
        assertTrue c.hasErrors()
        assertTrue c.errors.hasFieldErrors("password")
    }

    void testPasswordIsValid() {

        mockDomain(Customer)
        def c = new Customer(emailAddress:"kim@kardashian.com",password:"password", date:new Date())
		c.validate()
        assertFalse c.hasErrors()
        assertFalse c.errors.hasFieldErrors("password")
    }

     void testCreationDateFieldMissing() {

        mockDomain(Customer)
        def c = new Customer(emailAddress:"kim@kardashian.com",password:"password")
        c.validate()
        assertTrue c.hasErrors()
        assertTrue c.errors.hasFieldErrors("date")
    }
     void testCreationDateFieldValid() {

        mockDomain(Customer)
        def c = new Customer(emailAddress:"kim@kardashian.com",password:"password", date:new Date()  )
        c.validate()
        assertFalse c.hasErrors()
        assertFalse c.errors.hasFieldErrors("date")
    }
}
